package com.yunfei.core.utils.id;

import com.yunfei.core.utils.DateUtil;
import com.yunfei.core.utils.SnowflakeIdWorker;

import java.util.ArrayList;
import java.util.List;

public class IdUtils {
    /**
     * 主键生成策略
     * 时间戳+9位随机数
     * @return
     */
    public static  String getId(){
        String time=DateUtil.getAllTime();
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
        String id=time+idWorker.nextId();
        return id;
    }
    public static List<String> getIds(int length){
        List<String> list=new ArrayList<>();
        String time=DateUtil.getAllTime();
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
        for (int i = 0; i < length; i++) {
            String id = time+idWorker.nextId();
            list.add(id);
        }
        return list;
    }
    public static void main(String args[]){
        String time=DateUtil.getAllTime();
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
        for (int i = 0; i < 10000; i++) {
            String id = time+idWorker.nextId();
            if(id.length()!=32){
                System.out.println("我不是**************************************************************************************************************************************************");
            }
            System.out.println("id====="+id+",长度=============="+(id+"").length());
        }
    }
}
